<!DOCTYPE html>
<html lang="en" style="height: 100%">
<head>
    <meta charset="utf-8">
</head>
<body style="height: 100%; margin: 0">
<div id="container" style="height: 100%"></div>


<script type="text/javascript" src="https://fastly.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
<script src="assets/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript">

    // 获取学生成绩数据
    $.ajax({
        type: "POST",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        url: "/score/getScoreAccount",//url
        data: {},
        success: function (result) {
            if (result.code === "0") {
                // 处理成功返回的数据
                //console.log(result);
                let dom = document.getElementById('container');
                let myChart = echarts.init(dom, null, {
                    renderer: 'canvas',
                    useDirtyRect: false
                });
                let app = {};
                let option;
                // 动态创建series数组，数量等于第一个数组的长度减一
                let seriesArray = [];
                let subjectCount = result.data[0].length - 1;
                for (let i = 0; i < subjectCount; i++) {
                    seriesArray.push({type: 'bar'});
                }
                option = {
                    legend: {},
                    tooltip: {},
                    dataset: {
                        source: result.data
                    },
                    xAxis: {type: 'category'},
                    yAxis: {},
                    series: seriesArray
                };

                if (option && typeof option === 'object') {
                    myChart.setOption(option);
                }

                window.addEventListener('resize', myChart.resize);
            }else{
                alert(result.msg);
            }
        },
        error : function() {
            layer.msg('服务器错误', {
                icon: 5
            });
        }
    });

</script>
</body>
</html>